package com.lxf.education.service.impl;

import javax.annotation.Resource;

import com.lxf.education.dao.TeacherListMapper;
import com.lxf.education.pojo.StudentPojo;
import com.lxf.education.pojo.TeacherPojo;
import com.lxf.education.service.TeacherListService;
import com.lxf.education.utils.ResultVo;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author:LuoXingFa;
* @version:Date:2022年4月28日下午4:57:33
*/
@Service
public class TeacherListServiceImpl implements TeacherListService {

	@Resource
	TeacherListMapper teacherListDao;

	/**
	 * 登录操作
	 */
	@Override
	public List<TeacherPojo> findTea(String loginName, String loginPwd) {
		// TODO Auto-generated method stub
		
		return teacherListDao.findTeacher(loginName,loginPwd);
	}

	/**
	 * 查询所有数据
	 * @return
	 */
	@Override
	public ResultVo getAll() {
		List<TeacherPojo> teacherPojoList = teacherListDao.findAll();
		if (teacherPojoList!=null){
			return ResultVo.getSuccessVo("success",teacherPojoList);
		}
		return  ResultVo.getFailVo("fails");
	}

	/**
	 * 分页查询
	 * @param page
	 * @param limit
	 * @return
	 */
	@Override
	public ResultVo getTeacherList(Integer page, Integer limit) {
		// TODO Auto-generated method stub
		try {
			//计算出初始页
			Integer start = (page-1)*limit;
			//查询数据
			List<TeacherPojo> teacherPojoList = teacherListDao.findAllTeacher(start,limit);
			//查询总条数
			int count = teacherListDao.finCount();
			ResultVo successVo = ResultVo.getSuccessVo("success",teacherPojoList);
			//将总条数设置进去
			successVo.setCount(count);
			return successVo;

		}catch (Exception e){
			e.printStackTrace();
			return ResultVo.getFailVo("fails");
		}
	}

	/**
	 * 单行查看
	 * @param id
	 * @return
	 */
	@Override
	public TeacherPojo selById(Integer id) {
		return teacherListDao.lookOneById(id);
	}

	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@Override
	public ResultVo delAllTea(Integer[] ids) {
		teacherListDao.delAllTeacher(ids);
		return ResultVo.getSuccessVo("success");
	}

	/**
	 * 根据id删除
	 * @param id
	 * @return
	 */
	@Override
	public ResultVo delTeacherById(Integer id) {
		teacherListDao.delTeacherById(id);
		return ResultVo.getSuccessVo("success");
	}

	/**
	 * 根据id更正内容
	 * @param id
	 * @param value
	 * @return
	 */
	@Override
	public ResultVo updateTeacher(Integer id, String value) {
		TeacherPojo teacherPojo = new TeacherPojo();
		teacherPojo.setTid(id);
		teacherPojo.setLoginPwd(value);
		teacherPojo.setTcollege(value);
		teacherPojo.setTmajor(value);
		teacherPojo.setTtitle(value);

		 teacherListDao.updateTeacher(teacherPojo);
		return ResultVo.getSuccessVo("success");
	}

	/**
	 *@查询个人信息
	 */
	@Override
	public StudentPojo findStuByName(String name) {
		// TODO Auto-generated method stub
		return teacherListDao.findTeaProfile(name);
	}

	@Override
	public List<TeacherPojo> getTeacherById(Integer tid) {
		return teacherListDao.getTeacherById(tid);
	}


}
